﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ComputerArchitecture.Core;
using ComputerArchitecture.Core.Logging;
using ComputerArchitecture.Numbers;
using ComputerArchitecture.Units.Interfaces;

namespace ComputerArchitecture.Units.Complement
{
    public class ComplementCompareUnit : LoggingObject, ICompareUnit
    {
        #region Fields

        private readonly ISubstractUnit _substractUnit;

        #endregion

        #region Constructors

        public ComplementCompareUnit(ILoggingService loggingService, ISubstractUnit substractUnit)
            : base(loggingService)
        {
            ArgumentValidator.NullValidate(substractUnit);
            _substractUnit = substractUnit;
        }

        #endregion

        public int Compare(ISignedBitNumber first, ISignedBitNumber second)
        {
            ArgumentValidator.NullValidate(first);
            ArgumentValidator.NullValidate(second);
            bool overflow;
            ISignedBitNumber result = _substractUnit.Substract(first, second, out overflow);
            return result.IsZero ? 0 : result.Sign;
        }
    }
}